<%@ page contentType="text/html;charset=UTF-8" language="java"  %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%--使用jstl获取指定格式的当前日期--%>
<jsp:useBean id="now" class="java.util.Date" />
<fmt:formatDate value="${now}" pattern="yyyy年MM月dd日" var="date" />
<html>
<head>
    <title>代理商管理系统</title>
    <link type="favicon" rel="shortcut icon" href="${ctx}/statics/img/favicon.ico" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/css/main.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/color.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/demo.css" />
    <script src="${ctx}/statics/easyui/jquery.min.js" type="text/javascript"></script>
    <script src="${ctx}/statics/easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="${ctx}/statics/easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
</head>
<body class="easyui-layout" >
    <div data-options="region:'north',split:false"
         style="background-image:url('${ctx}/statics/img/head-background.jpg');background-repeat: no-repeat;height:30px;line-height:28px" >
        <span style="margin-left:70%;font-size:13px">欢迎您:[${sessionScope.user.userName}]&nbsp;今天是${date}&nbsp;
            <a href="${ctx}/do/exit" style="font-size:13px;color:blue;text-decoration:none">退出系统</a>&nbsp;<a href="#" style="font-size:13px;color:blue;text-decoration:none" onclick="showEditPassWin()" >修改密码</a>
        </span>
        <div id="winUser" class="easyui-window" style="width:500px;height:260px;" title="修改密码"
             data-options="iconCls:'icon-save',modal:true,closed:true">
            <div class="easyui-layout" data-options="fit:true">
                <div data-options="region:'north',split:false" style="height:40px;line-height:38px;text-align:center" ><span>修改密码</span></div>
                <div data-options="region:'center'" style="text-align:center">
                    <form id="userForm" method="post" >
                        <table id="ct" style="margin:20px auto;" cellpadding="5px">
                            <tr>
                                <td>请输入原密码:</td>
                                <td><input id="oldUserPassword" class="easyui-textbox" type="text" name="oldUserPassword" style="width:120px"
                                           data-options="required:true,missingMessage:'密码不能为空'" />
                                </td>
                                <td><span id="oldUserPasswordError" style="color:red">您本次登陆的密码</span></td>
                            </tr>
                            <tr>
                                <td>请输入新密码:</td>
                                <td><input id="userPassword" class="easyui-textbox" type="text" name="userPassword" style="width:120px"
                                           data-options="required:true,missingMessage:'密码不能为空'" />
                                </td>
                                <td><span id="userPasswordError" style="color:red">新密码不少于6个字符</span></td>
                            </tr>
                            <tr>
                                <td>请确认新密码:</td>
                                <td><input id="userPassword2" class="easyui-textbox" type="text" style="width:120px"
                                           data-options="required:true,missingMessage:'密码不能为空'" />
                                </td>
                                <td><span id="userPassword2Error" style="color:red">新密码不少于6个字符</span></td>
                            </tr>
                        </table>
                    </form>
                </div>
                <div data-options="region:'south',border:false" style="text-align:right;height:40px;padding:7px 10px 5px">
                    <a id="confirm" class="easyui-linkbutton" data-options="iconCls:'icon-ok',size:'small'" href="javascript:void(0)"
                       onclick="submitForm()" style="width:80px">确定</a>
                    <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel',size:'small'" href="javascript:void(0)"
                       onclick="closeWin()" style="width:80px">取消</a>
                </div>
            </div>
        </div>
    </div>
    <div data-options="region:'south',split:false" style="height:20px;text-align:center;background-color:#E8F1F9">
        <span>北京XXX责任有限公司</span>
    </div>
    <div data-options="region:'west',title:'-功能菜单-',split:true" style="width:200px;">
        <div id="aa" class="easyui-accordion" data-options="fit:true" style="border:0">
            <c:forEach items="${requestScope.userFuncMap}" var="list" >
                <div title="${list.key}" data-options="iconCls:'icon-tabicons_fb'" style="padding:10px" >
                    <ul style="list-style:none;padding-left:10px">
                        <c:forEach items="${list.value}" var="list2" >
                            <li style="margin-top:20px;" >
                                    <a class="easyui-linkbutton c6" href="${ctx}/do/${list2.value}"
                                       target="mainFrame" onclick="tabName('${list2.key}')"
                                       style="width:120px;text-align:left" >
                                        <span>${list2.key}</span>
                                    </a>
                            </li>
                        </c:forEach>
                    </ul>
                </div>
            </c:forEach>
        </div>
    </div>
    <div data-options="region:'center'" style="background:#eee;">
        <div id="tt" class="easyui-tabs"   >
            <div id="tab" title="首页"  >
                <div id="welcome" style="padding-left:20px;padding-top:20px">
                    <h2>你好,${sessionScope.user.userName}</h2>
                    <p style="font-size:15px">您当前账户余额为:<span style="color:red;font-size:15px">${requestScope.money}</span>元</p>
                    <p><a href="javascript:void(0)" class="easyui-linkbutton c1" style="width:120px;" onclick="viewAccount()" >查看账户明细</a> </p>
                </div>
                <div id="winAccount" class="easyui-window" style="width:1000px;height:500px;" title="账户明细"
                     data-options="iconCls:'icon-save',modal:true,closed:true">
                    <div class="easyui-layout" data-options="fit:true">
                        <div data-options="region:'north',split:false" style="height:40px;line-height:38px;text-align:center" ><span>查看账户明细</span></div>
                        <div data-options="region:'center'" style="text-align:center">
                            <table id="agentPreDg" style="width:100%;"></table>
                        </div>
                    </div>
                </div>
                <iframe id="mainFrame" name="mainFrame" style="width:100%;height:97%;border:none;"></iframe>
            </div>
        </div>
    </div>
    <script>

        //函数用户更新选项卡title
        function tabName( name )
        {
            $("#welcome").hide();
            //获取选项卡
            var panel = $("#tt").tabs('getTab',0);
            //panel.panel('setTitle' , "111" );
            //使用获取的选项卡更改标题
            $('#tt').tabs('update',
                {
                    tab:panel,
                    options:{ title:name }
                });
        }

        //查看账户明细
        function viewAccount()
        {
            $("#agentPreDg").datagrid({
                url:'${ctx}/do/showAgentPrePayManage',
                singleSelect:true,
                fitColumns:true,
                striped:true,
                fit:true,
                rownumbers:true,
                pagination:true, //增加分页工具栏
                pageNumber:1, //设置初始化页码
                pageSize:10,  //页大小
                pageList:[5,10,15], //显示数量选择
                columns:
                    [
                        [
                            {field:'id',title:'序号',width:'5%',align:'center'},
                            {field:'money',title:'账务资金',width:'7%',align:'center'},
                            {field:'accountMoney',title:'账户余额',width:'7%',align:'center'},
                            {field:'memo',title:'备注信息',width:'55%',align:'center'},
                            {field:'detailDateTime',title:'交易时间',width:'15%',align:'center'}
                        ]
                    ]
            });
            $("#winAccount").window('open');
        }

        //显示修改密码窗口
        function showEditPassWin()
        {
            clearTextbox();
            clearError();
            $("#winUser").window('open');
        }

        //点击确定提交修改密码
        function submitForm()
        {
            //首先检验新密码和确认密码是否一致
            var newPass = $("#userPassword").textbox('getValue');
            var newPass2 = $("#userPassword2").textbox('getValue');
            if( newPass !== newPass2 )
            {
                $.messager.alert('修改密码','输入的新密码和确认新密码不一致,请检查后重新输入' , 'warning');
            }
            else
            {
                //一致发送修改密码请求
                $("#userForm").form('submit' ,
                    {
                        url:"${ctx}/do/updateUserPass",
                        success:function ( data )
                        {
                            var json = JSON.parse(data);
                            if( json.errorMessage )
                            {
                                var errorMessage = json.errorMessage;
                                if( errorMessage.oldUserPassword )
                                {
                                    $("#oldUserPasswordError").text(errorMessage.oldUserPassword);
                                }
                                else
                                {
                                    $("#oldUserPasswordError").text("新密码不少于6个字符");
                                }
                                if( errorMessage.userPassword )
                                {
                                    $("#userPasswordError").text(errorMessage.userPassword);
                                    $("#userPassword2Error").text(errorMessage.userPassword);
                                }
                                else
                                {
                                    $("#userPasswordError").text("新密码不少于6个字符");
                                    $("#userPassword2Error").text("新密码不少于6个字符");
                                }
                            }
                            else
                            {
                                //清除错误消息提示
                                clearError();
                                if( json.message ==  1 )
                                {
                                    $.messager.alert('修改密码','密码修改成功' , 'info' );
                                }
                                else
                                {
                                    $.messager.alert('修改密码','密码修改失败' , 'info' );
                                }
                                clearTextbox();
                                closeWin();
                            }

                        }
                    }
                )
            }
        }

        //清空密码输入框
        function clearTextbox()
        {
            $("#oldUserPassword").textbox("clear");
            $("#userPassword").textbox("clear");
            $("#userPassword2").textbox("clear");
        }

        //清空校验错误提示
        function clearError()
        {
            $("#oldUserPasswordError").text("您本次登陆的密码");
            $("#userPasswordError").text("新密码不少于6个字符");
            $("#userPassword2Error").text("新密码不少于6个字符");
        }

        //关闭窗口
        function closeWin()
        {
            $('#winUser').window('close');
        }
    </script>
</body>
</html>
